package cn.tianyigps.tianyigpsbatterylockalarm.hanlder;

import cn.tianyigps.tianyigpskafka.task.bean.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

/**
 * @Author: WEI.YUAN
 * @Descirption:redis规则处理
 * @Date: 2019/4/17_16:18
 */
@Component
public class BatteryRuleUtil {
    @Autowired
    RedisTemplate redisTemplate;
    /**
     * 添加规则
     */
    public void addBatterRule(Task task) {
        try {
            String eqId = task.getParams().get("equipmentId").toString();
            redisTemplate.opsForValue().set(eqId + "BatteryRule", task);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 删除规则
     *
     * @param task
     */
    public void delBatterRule(Task task) {
        try {
            String eqId = task.getParams().get("equipmentId").toString();
            redisTemplate.delete(eqId + "BatteryRule");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
